import java.util.*;

public class DAO<T> {
    Map<String, T> list;

    public DAO() {
        list = new HashMap<>();
    }

    public void save(String id, T entity) {
        list.put(id, entity);
    }

    public T get(String id) {
        return list.get(id);
    }

    public void update(String id, T entity) {
        if (list.containsKey(id)) {
            list.put(id, entity);
        } else {
            System.out.println("数据不存在，无法更新");
        }

    }

    public void delete(String id) {
        if (list.containsKey(id)) {
            list.remove(id);
        } else {
            System.out.println("数据不存在，无法删除");
        }
    }

    public List<T> list() {
        return Collections.unmodifiableList(new ArrayList<T>(list.values()));
    }
}
